package com.thebox.config;

import java.util.*;

public class Param {
    private String name = null;
    private String category = null;
    private String type = null;
    private Object value = null;

    public Param() {
    }

    public void setName(String str) {
        name = str;
    }

    public void setCategory(String str) {
        category = str;
    }

    public void setType(String str) {
        type = str;
    }

    public void setValue(String str) {
        value = str;
    }

    public void setParam(String n, String c, String t, String v) {
        name = n;
        category = c;
        type = t;
        if (type.equalsIgnoreCase("String[]")) {
            //String [] parameter is a string seperated by ","
            StringTokenizer s = new StringTokenizer(v, ",");
            LinkedList l = new LinkedList();
            while (s.hasMoreTokens()) {
                l.add(s.nextToken().trim());
            }
            value = new String[l.size()];
            l.toArray((String[])value);
        } else {
            value = v;
        }
    }

    public String getName() {
        return name;
    }

    public String getCategory() {
        return category;
    }

    public String getType() {
        return type;
    }

    public Object getValue() {
        return value;
    }

    public String toString() {
        String newline = System.getProperty("line.separator");
        StringBuffer buf = new StringBuffer();

        buf.append("Param - ").append(name).append(newline);
        buf.append("\tCategory=").append(category).append(newline);
        buf.append("\tType=").append(type).append(newline);
        buf.append("\tvalue=");
        if ("String[]".equalsIgnoreCase(type)) {
            buf.append(Arrays.asList((String[])value));
        } else {
            buf.append((String)value);
        }

        buf.append(newline);

        return buf.toString();
    }

    public static void debug(Object obj) {
        System.out.println("From Param.java: " + obj);
    }
}
